<?php echo $this->Html->script(array('jquery.quicksearch','actions'),$options = array('allowCache'=>false,'safe'=>false,'inline'=>false));?>
<?php echo $this->Html->css(array('actions','messages','events.lists','lastminute-left','search-left','form'),null,array('inline'=>false));?>


<?php
echo $javascript->codeBlock("
	$(document).ready(function(){
		$('#button_lista_uzytkownikow').click(function() {
		  $('#dialog_lista_uzytkownikow').dialog({width: 650, height: 600});
		});
		
		$('.chackbox_select_user').click(function(){
			UserID = $(this).val();
			if ( this.checked ){
		  		$('#MessageUsers').val($('#MessageUsers').val() + $(this).attr('title') + ';');
		  		$('#MessageUserId'+UserID).attr('value',UserID);
		  	}else{
		  		tresc = $('#MessageUsers').val();
		  		$('#MessageUsers').val(tresc.replace($(this).attr('title')+';', ''));
		  		$('#MessageUserId'+UserID).attr('value',0);
		  	}
		});
		
		$('input#id_search').quicksearch('table#table_users_list tr');
	});		
",$options = array('allowCache'=>false,'safe'=>false,'inline'=>false));
?>

<div class="content">
	<div class="left-column">
		<?php echo $this->Yachts->search_form_left();?>		
		<div class="clr"></div>	
		<?php echo $this->Yachts->lastminute(2);?>
		<div class="clr"></div>	
	</div>
	
	
	<div class="middle-column main-column">
		<div class="box corners">		

		<?php //echo $this->Form->create('Message');?>
		<?php
			echo $javascript->link('ckeditor/ckeditor');
			echo $cksource->create(__("Message",true),array('url'=>array('action'=>'edit'))); 
			$config['toolbar'] = array( 
			    array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ), 
			    array( 'Image', 'Link', 'Unlink', 'Anchor' ) 
			); 
			$config['height'] = 350;
		?>		
			
				<h2><?php __('Re Send Message'); ?></h2>
		 		
		 		
				<div class="actions">
					<ul>
						
						<li><?php echo $this->Html->link(__("New", true), array( 'action' => 'add'),array('escape'=>false,'title'=>__("New", true),'class'=>'new-message')); ?></li>
						<li><?php echo $this->Html->link(__("Inbox", true), array( 'action' => 'index',1),array('escape'=>false,'title'=>__("Inbox", true),'class'=>'inbox')); ?></li>
						<li><?php echo $this->Html->link(__("Outbox", true), array( 'action' => 'index',2),array('escape'=>false,'title'=>__("Outbox", true),'class'=>'outbox')); ?></li>				
						<li><?php echo $this->Html->link(__("Archives", true), array( 'action' => 'index',3),array('escape'=>false,'title'=>__("Archives", true),'class'=>'archive')); ?></li>				
						<li><?php echo $this->Html->link(__("Deleted", true), array( 'action' => 'index',4),array('escape'=>false,'title'=>__("Deleted", true),'class'=>'deleted')); ?></li>
						<li><?php echo $this->Html->link(__("Delete", true), array( 'action' => 'delete',$this->Form->value('Message.id')),array('escape'=>false,'title'=>__("Delete", true),'class'=>'delete'), sprintf(__("Are you sure you want to delete # %s?", true), $this->Form->value('Message.id'))); ?></li>
					</ul>
				</div>
		
		 		<table width="100%">
		 			<tr>
		 				<td>
		 					<?php echo __("To",true)?>
		 				</td>
		 				<td>
		 					<?php echo $this->Form->input('users',array('label'=>false,'type'=>'text','style'=>'width: 100%;'));?>
		 					<?php
		 						$from_uId = $this->data['Message'][(($this->data['Message']['status']==1 || $this->data['Message']['status']==3 || $this->data['Message']['status']==41 || $this->data['Message']['status']== 43)?'fromto_':'').'user_id'];
		 						$to_uId = $this->data['Message'][(($this->data['Message']['status']==1 || $this->data['Message']['status']==3 || $this->data['Message']['status']==41 || $this->data['Message']['status']== 43)?'':'fromto_').'user_id'];
			
		 					?>
		 					<?php 
		 						foreach ($users as $user_id => $user){
		 							if($from_uId == $user_id){
		 								echo $this->Form->hidden('user_id.'.$user_id,array('value'=>$user_id));
		 							}else if($to_uId == $user_id ){
		 								echo $this->Form->hidden('user_id.'.$user_id,array('value'=>$user_id));
		 							}else{
		 								echo $this->Form->hidden('user_id.'.$user_id,array('value'=>0));
		 							}
		 						}
		 					?>
		 				</td>
		 				<td align="left"><input id="button_lista_uzytkownikow" type="button" value="..."/></td>
		 			</tr>
		 			<tr>
		 				<td><?php echo  __("Subject",true)?></td>
						<td colspan="2">
							<?php echo $this->Form->input('name',array('label'=>false,'style'=>'width: 100%;'));?>
						</td>
		 			</tr>
		 		</table>
			<?php 

				
				$from = "<strong>".__("From: ",true)."</strong>". ((isset($users["{$from_uId}"]['name']))?$users["{$from_uId}"]['name']:'');
 				$sent = "<br/><strong>".__("Sent: ",true)."</strong/>". date('l, F d, Y H:i A'); 
				
 				$to = "<br/><strong>".__("To: ",true)."</strong>". ((isset($users["{$to_uId}"]['name']))?$users["{$to_uId}"]['name']:'');
				
				$subject = "<br/><strong>".__("Subject: ",true)."</strong>". $this->data['Message']['name'];	
				$content = "<br/><br/>". $this->data['Message']['content'];		
				echo $cksource->ckeditor('Message.content', array( 'config'=>$config, 
					'value'=>"<br/><br/><hr/>".$from.$sent.$to.$subject.$content));
				echo $this->Form->hidden('fromto_user_id');
				echo $this->Form->hidden('status');
			?>
			
		<?php echo $this->Form->end(__('Send', true));?>
		</div>
		
		<div id="dialog_lista_uzytkownikow" title="<?php echo __("Users List",true)?>">
 			<div class="select_user_from_list index">
			<form action="#">
				<fieldset>
						<div class="input text required">
						<label for="search"><?php __("Szukaj")?></label>
						<input type="text" name="search" value="" id="id_search" placeholder="Search" autofocus=""/>
						</div>
				</fieldset>
			</form>
			<table cellpadding="0" cellspacing="0" id="table_users_list">
				<?php
				$i = 0;
				foreach ($users as $user_id => $user):
					$class = null;
					if ($i++ % 2 == 0) {
						$class = ' class="altrow"';
					}
				?>
				<tr<?php echo $class;?>>
					<td>
						<?php $checked = (isset($this->data["Message"]["user_id"]) && is_array($this->data["Message"]["user_id"]) && array_key_exists($user_id, $this->data["Message"]["user_id"]) && $this->data["Message"]["user_id"][$user_id] == $user_id ) ? "checked": ""?>
						<?php echo $this->Form->checkbox('users.'.$user_id,array('class'=>'chackbox_select_user','value'=>$user_id,'title'=>$user['email'], 'checked'=>$checked) );?>
					</td>
					<td><?php // echo $user['email']; ?> &nbsp;</td>
					<td><?php echo $user['name']; ?>&nbsp;</td>
	
				</tr>
			<?php endforeach; ?>
				</table>					
 			</div>
 		</div>
	 					
		<div class="clr"></div>	
	</div>			
	<div class="right-column">
		<?php echo $this->element('user_main_left_menu')?>
	</div>		
	<div class="clr"></div>
</div>	
<div class="clr"></div>	